#include "client.h"

#define READ_DATA_SIZE	1024
#define MD5_SIZE		16
#define MD5_STR_LEN		(MD5_SIZE * 2)

int sendFile(int sockfd,const char* filename){
    sendMd5(sockfd,filename);

    int sendlength;
    recvn(sockfd,&sendlength,sizeof(int));
    if(sendlength == 0){
        printf("Quickly uploaded the file successfully \n");
        fflush(stdout);
    }else{
        int fd = open(filename,O_RDWR);
        if(fd == -1){
            printf("The file open failed\n");
            fflush(stdout);
        }
        struct stat statbuf;
        fstat(fd,&statbuf);
        sendlength = (int)(statbuf.st_size);
        send(sockfd,&sendlength,sizeof(int),MSG_NOSIGNAL);
        sendfile(sockfd,fd,NULL,statbuf.st_size);
        close(fd);
        return 0;
    }
    printf("Uploaded file success\n");
    fflush(stdout);
    return 0;
}
